package com.library.mapper;


import com.library.annotation.AutoFill;
import com.library.entity.User;
import com.library.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    /**
     * 新增用户
     * @param user
     */
    @Insert("insert into user(username, password, role, phone, email, avatar, biography, create_time, update_time)" +
            "values" +
            " (#{username}, #{password}, #{role}, #{phone}, #{email}, #{avatar}, #{biography}, #{createTime}, #{updateTime})"
            )
    @AutoFill(value = OperationType.INSERT)
    void insert(User user);

    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    @Select("select * from user where id = #{id}")
    User getById(Long id);

    /**
     * 修改用户角色
     * @param userId
     * @param role
     */
    @Update("update user set role = #{role} where id = #{userId}")
    void updateUserRole(Long userId, Integer role);

    /**
     * 修改用户信息
     * @param user
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(User user);
}
